
* +++++++++++++++++++++++++++++
* TABLE 6: 
* COUNTY-LEVEL MULTIVARIATE
* RELATIONSHIPS WITH INTEGRATION
* +++++++++++++++++++++++++++++

* load data
use "${data_derived}/regional_analysis_data.dta",clear

* FB variables for which we want to make regression table (code takes logs of these)
local fb_int "integration gen_friendliness relative_friending language"

* shorten some variable names, otherwise they get to long when we create logs
ren *teach* *tch*
ren *gen_schl* *gen_sc*
ren *unemp_uni* *unemp_he*

* create logs
foreach var of varlist n_frnd_nat_lcl_sy_nat_avg_re n_frnd_nat_lcl_sy_avg_re ///
	n_frnd_nat_lcl_native_avg_re produ_any_de_sy_avg_re frac_emp_train_any_syria ///
	unemp_* {
	cap gen log_`var' = log(`var')
	ren `var' raw_`var'

}

* give FB integration measures better variable names
gen log_integration        = log_n_frnd_nat_lcl_sy_avg_re
gen log_gen_friendliness   = log_n_frnd_nat_lcl_native_avg_re
gen log_relative_friending = log_n_frnd_nat_lcl_sy_nat_avg_re
gen log_language           = log_produ_any_de_sy_avg_re

* select RHS variables
local rhs "avg_age log_pop_dens_2018 log_avg_inc log_unemp_tot2014_per_pop afd_2014_dev_st per_pop_proasyl_groups log_frac_syr_tot_2010 log_frac_syr_tot_2019 log_per_syr_cours_compl_15_19" 

* set fraction of Syrians in 2010 to minimum if missing
sum log_frac_syr_tot_2010, d
replace log_frac_syr_tot_2010 = `r(min)' if log_frac_syr_tot_2010 == .

* rescale ProAsyl groups
replace per_pop_proasyl_groups = per_pop_proasyl_groups * 1000

* run regressions for various measures integration and components
* with and without state fixed effects
eststo clear
local i = 1
foreach int_var in `fb_int' { 
	* if general friendliness is the outcome of interest we weight by native
	* population, otherwise by Syrian population
	if "`int_var'" == "gen_friendliness"  		local weights "n_frnd_nat_lcl_native_n"
	else  										local weights "n_frnd_nat_lcl_sy_n"
	eststo reg`i' : reg log_`int_var' `rhs' [w=`weights'], robust
	estadd local stateFE No
	local ++i
	eststo reg`i' : reg log_`int_var' `rhs' [w=`weights'], robust absorb(state)
	estadd local stateFE Yes
	local ++i
}

esttab * using "${output}/county_lvl_reg_measures_of_integr.csv", replace ///
	cells(b(star fmt(3)) se(par fmt(2))) legend ///
	starlevels(* 0.10 ** 0.05 *** 0.010) drop(_cons) ///
	stats(stateFE r2 N mean, labels("State FE" "R-squared")) label
